package com.world.business.belief.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.world.business.belief.domain.Belief;
import com.world.business.belief.domain.query.BeliefAddRequest;
import com.world.business.belief.domain.query.BeliefPageRequest;
import com.world.business.belief.domain.query.BeliefUpdateRequest;
import com.world.business.belief.domain.vo.BeliefVO;
import com.world.business.belief.service.IBeliefService;
import com.world.common.controller.BaseController;
import com.world.common.domain.PageResult;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 信仰 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-07-31
 */
@Api(tags = "信仰")
@RestController
@RequestMapping("/belief")
public class BeliefController extends BaseController<Belief> {

    @Resource
    private IBeliefService beliefService;

    @ApiOperation("分页列表")
    @GetMapping("/page")
    public ResponseData<PageResult<BeliefVO>> page(BeliefPageRequest request) {
        IPage<BeliefVO> page = beliefService.getPage(startPage(request), request);
        return new SuccessResponseData<>(getPageResult(page));
    }

    @ApiOperation("新增")
    @PostMapping("")
    public ResponseData<Long> add(@Validated @RequestBody BeliefAddRequest request) {
        return new SuccessResponseData<>(beliefService.add(request));
    }

    @ApiOperation("修改")
    @PutMapping("")
    public ResponseData<Void> delete(@Validated @RequestBody BeliefUpdateRequest request) {
        beliefService.update(request);
        return new SuccessResponseData<>();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseData<Void> delete(@PathVariable("id") Long id) {
        beliefService.delete(id);
        return new SuccessResponseData<>();
    }
}
